home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16035 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: ix.netcom.com!news
  2. From: jhewett@ix.netcom.com (Jerry Hewett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Button Problem???
  5. Date: Mon, 08 Apr 96 16:32:50 GMT
  6. Organization: Netcom
  7. Message-ID: <N.040896.093250.56@ix.netcom.com>
  8. References: <4k5v31$7rs@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: tem-ca1-18.ix.netcom.com
  10. X-NETCOM-Date: Mon Apr 08 11:33:21 AM CDT 1996
  11. X-Newsreader: Quarterdeck Message Center [2.00]
  12.  
  13. > I have a Visual C++ 1.52 MFC project that uses buttons in a CFormView. How
  14. > can I make a button toggle on/off every time it's pressed.
  15.  
  16. Unless there's a new kind of custom control for pushbuttons in the MFC, you'll 
  17. have to either use another control (a radio button or check box, for example) 
  18. or design your own OWNERDRAW pushbutton.  As far as I know, the standard 
  19. pushbutton will only stay down while you're click-select on it, and will always 
  20. "pop" back up when you click-release the mouse.
  21.  
  22. You can find an example of an OWNERDRAW pushbutton in Chapter 6 of _Programming 
  23. Windows 3.1_ and/or Chapter 8 of _Programming Windows 95_ by Charles Petzold 
  24. (Microsoft Press).
  25.  
  26. Hmmm... hold on a second!  This looks promising.  I was thumbing through Part 
  27. One of the MFC Reference and came across CButton::SetBitmap on page 132, which 
  28. contains the following under the REMARKS section:
  29.  
  30.     "Unlike CBitmapButton, which uses four bitmaps per button, SetBitmap
  31.      uses only one bitmap per button.  When the button is pressed, the
  32.      bitmap appears to shift down and to the right."
  33.  
  34. Ah-ha!  Take a look at CBitmapButton on pages 112-113!  There *is* a new custom 
  35. control, with a step-by-step guide on how to include CBitmapButton's in you 
  36. dialog and instructions on how to change the button state between UP, DOWN, 
  37. FOCUSED, and DISABLED.
  38.  
  39. Edit your dialog box with the Resource Editor, and add BS_PUSHLIKE to the 
  40. button's parameter list.  In theory (since I'm just reading the instructions 
  41. and not writing a sample program to test it :-) this should allow Windows 95 to 
  42. control the pushbutton's appearance.  The first time you click-select the 
  43. pushbutton Win95 will change it to a DOWN state, and the next time it's clicked 
  44. it should return to the UP state.  For absolute control over the pushbutton's 
  45. appearance you might have to add routines to handle BM_GETSTATE and BM_SETSTATE 
  46. in your button class.
  47.  
  48. Huh!  I learned something new today! 8-)
  49.  
  50. Jerry ("Not An MFC Guru.  Yet") H.
  51.  
  52.  
  53.